package com.example.demo.model;

import com.baidu.bas.annotation.Erupt;
import com.baidu.bas.annotation.EruptField;
import com.baidu.bas.annotation.model.English;
import com.baidu.bas.annotation.sub_field.Edit;
import com.baidu.bas.annotation.sub_field.EditType;
import com.baidu.bas.annotation.sub_field.View;
import com.baidu.bas.annotation.sub_field.sub_edit.ChoiceType;
import com.baidu.bas.upms.handler.DictChoiceFetchHandler;
import com.baidu.bas.upms.model.base.HyperModel;
import com.deepzero.mmma.channel.vo.def.Variable;
import com.example.demo.model.custom.ChannelDataProxy;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import java.util.List;

/**
 * @author liuzhenchuan@foxmail.com
 * @date 2020/12/21
 */
@Setter
@Getter
@Erupt(name = "渠道",dataProxy={ChannelDataProxy.class})
@Table(name = "ma_channel",uniqueConstraints = {
        @UniqueConstraint(columnNames = "name")
})
@Entity
@NoArgsConstructor
public class Channel extends HyperModel {
    /**
     * name
     */
    @EruptField(
            views = @View(title = "名称"),
            edit = @Edit(title = "名称")
    )
    private String name;
    /**
     * type
     */
    @EruptField(
            views = @View(title = "账号类型"),
            edit = @Edit(title = "账号类型",type = EditType.HIDDEN)
    )
    private String accountType;
    /**
     * 渠道中要填写的字段
     */
    @Type(type = "json")
    @Column(name = "defines", columnDefinition = "json")
    @EruptField(
            views = @View(title = "定义"),
            edit = @Edit(title = "定义",type = EditType.HIDDEN)
    )
    List<Variable> defines;
    /**
     * 类型
     */
    @EruptField(
            views = @View(title = "类别"),
            edit = @Edit(title = "类别",type = EditType.CHOICE,
                    choiceType = @ChoiceType(
                            fetchHandler = DictChoiceFetchHandler.class,
                            fetchHandlerParams = "channel_category"
                    ))
    )
    private String category;

    /**
     * name
     */
    @EruptField(
            views = @View(title = "英文名称"),
            edit = @Edit(title = "英文名称")
    )
    @English(replace = "name")
    private String ename;


    public Channel(String name, String accountType, List<Variable> defines, String category) {
        this.name = name;
        this.accountType = accountType;
        this.defines = defines;
        this.category = category;
    }

    @EruptField(
            views = @View(title = "是否开启"),
            edit = @Edit(title = "是否开启")
    )
    Boolean enable = true;
}
